var updateInfoCtrl  = new XFApp.client();

XFApp.client.prototype.updateInfo = {
		successCode : 10000,
		urlItems : {
			updateURL: basePath+"/userCenter/logged/update",
		},
		
		formValidate : function(){			
			$("#editForm").validate({				
		        rules: {
		        	realName:"required",
		        	sex: "required",	
		        	email:{
        		  		required:true,
        		  		email: true
        			    },
        			mobile:{
        		       required:true,
        		       number:true
        	           },
				  },
				 messages: {	
					realName:"请填写真实姓名",
			        sex: "请选择性别",		        	           
			        email:{
	        	 		required:"请填写电子邮件",
	        	 		email:"电子邮件格式不正确"
	         			},
	         		mobile:{
	         			 required:"请填写手机号码",
	        	         number:"手机号码格式不正确"
	        	        },
				  }
		    });
			$("#editForm").validate();
		},
		
		RegisterTypes : function(value) {
			if(!value){
				return "";
			}
			for(index in registerTypes){
				var registerType = registerTypes[index];
				if(registerType.dictCode == value){
					return registerType.dictName;
				}
			}
			return  "未知类型("+value+")";
		},	
		
		event : function (){			
			_this = this;
			
			$("#submitBtn").on("click",function(){				
				if($("#editForm").validate().form()){
					updateInfoCtrl.updateInfo.submit();		
				}				
			});
			//表单验证
			_this.formValidate();	
			
			//翻译注册类型
			var userType = $("#userType").html();
			var registerType = _this.RegisterTypes(userType);
			$("#userType").html(registerType);
		},
		
		submit : function (){
			
			var sexVal ;
			
			$(":radio").each(function(){
				if($(this).prop("checked")){
					sexVal =  $(this).val()+"" ;
				}				   
			});
			
			var entity = {
				id : $("#hiddenId").val(),					
				realName : $("#realName").val(),
				mobile : $("#mobile").val(),					
				tel : $("#tel").val(),
				sex : sexVal,					
				email : $("#email").val(),
				postCode : $("#postCode").val(),
			}
			    	
			
		    $.ajax({
			url : _this.urlItems.updateURL,
			data : entity,
			dataType : "json",
			type : 'post',
			success : function(data) {
				if (data.code == _this.successCode) {
					window.webDialogUtil.alert("提示", data.msg);
				} else {
					window.webDialogUtil.alert("提示", data.msg);
				}
			}
		});	
			
	},
},

$(function(){	
	updateInfoCtrl.updateInfo.event();
});